﻿using System.Linq;
using CompactMapper.Orm.Queries;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CompactMapper.Orm.Tests
{
    [TestClass]
    public class OrmLikeQueriesTest : MusicDatabaseTestsBase
    {
        [TestMethod]
        public void OrmLikeQueriesTest_PercentOnLeft()
        {
            using (var unitOfWork = GetKeyedUnitOfWork<Artist>())
            {
                var query = new Query<Artist>().StringLike(a => a.ArtistName, "% Mode");
                var match = unitOfWork.GetByQuery(query).Single();
                Assert.AreEqual(MusicDatabasePopulation.ArtistName, match.ArtistName);
            }
        }

        [TestMethod]
        public void OrmLikeQueriesTest_PercentOnRight()
        {
            using (var unitOfWork = GetKeyedUnitOfWork<Artist>())
            {
                var query = new Query<Artist>().StringLike(a => a.ArtistName, "Dep%");
                var match = unitOfWork.GetByQuery(query).Single();
                Assert.AreEqual(MusicDatabasePopulation.ArtistName, match.ArtistName);
            }
        }

        [TestMethod]
        public void OrmLikeQueriesTest_PercentOnBothEnds()
        {
            using (var unitOfWork = GetKeyedUnitOfWork<Artist>())
            {
                var query = new Query<Artist>().StringLike(a => a.ArtistName, "%e M%");
                var match = unitOfWork.GetByQuery(query).Single();
                Assert.AreEqual(MusicDatabasePopulation.ArtistName, match.ArtistName);
            }
        }

        [TestMethod]
        public void OrmLikeQueriesTest_UnderscoreOnMiddle()
        {
            using (var unitOfWork = GetKeyedUnitOfWork<Artist>())
            {
                var query = new Query<Artist>().StringLike(a => a.ArtistName, "Depeche _ode");
                var match = unitOfWork.GetByQuery(query).Single();
                Assert.AreEqual(MusicDatabasePopulation.ArtistName, match.ArtistName);
            }
        }
    }
}
